#ifndef CHUNK_H
#define CHUNK_H


#include "includes.h"
#include "voxel.h"
#include "seeker.h"
#include "QuickArray.h"
#include "vbomanager.h"

class Chunk
{
    VBOManager* vbo;
    bool changed;
    voxel varr[CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE];
    //QuickArray<short>* inarr;
    int no_of_voxels;
    //seeker seek;
    uchar x,y,z;


    int vector_to_index(int x, int y, int z){
        return MUL_CHNKSIZE(MUL_CHNKSIZE(MOD_CHNKSIZE(x))) + MUL_CHNKSIZE(MOD_CHNKSIZE(y)) + MOD_CHNKSIZE(z);
    }

    inline vector3<int> index_to_vector(int index){
        int _z = MOD_CHNKSIZE(index);
        int _y = MOD_CHNKSIZE(DIV_CHNKSIZE(index - _z));
        int _x = DIV_CHNKSIZE(DIV_CHNKSIZE(index - MUL_CHNKSIZE(_y) - _z));
        return vector3<int>(_x+x,_y+y,_z+z);
    }

    void setWorldCoords(uchar _x, uchar _y, uchar _z);
    void drawVoxel(int index);
    //void renderWalk(seeker& seekr);
    void initVBO();
public:
    Chunk();
    voxel& getChunkVoxel(int x, int y, int z);
    void addChunkVoxel(int x, int y, int z, voxel& v);
    void removeChunkVoxel(int x, int y, int z);
    void setVoxelColor(int x, int y, int z, colour& c);
    bool IsEmpty();
    int getChunkVoxelCount();
    int worldX(){return x;}
    int worldY(){return y;}
    int worldZ(){return z;}
    void render();

friend class ChunkManager;
};

#endif // CHUNK_H
